package com.cwhuang.g7_tool_myhymns;

import java.util.ArrayList;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HymnAdapterOneLine extends BaseAdapter {
	public final static String COL_SERIAL = "col_serial";
	public final static String COL_INDEX = "col_index";
	public final static String COL_TITLE = "col_title";
	public final static String COL_RATING = "col_rating";
	public final static String COL_TIMES = "col_times";
	public final static String COL_FAMILIARITY = "col_familiarity";
	
	private ArrayList<Map<String, Object>> data;   
    private LayoutInflater layoutInflater;   
    @SuppressWarnings("unused")
	private Context context;  
    
    public HymnAdapterOneLine(Context context, ArrayList<Map<String, Object>> data) {   
        this.context = context;   
        this.data = data;   
        this.layoutInflater = LayoutInflater.from(context);   
    }  
    
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Hymn hymn = null;
		
		if(convertView == null){
			hymn = new Hymn();
			convertView = layoutInflater.inflate(R.layout.listlayout_1_line, null);
			hymn.textView_index =(TextView)convertView.findViewById(R.id.list_oneline_txt_index);
			hymn.textView_title =(TextView)convertView.findViewById(R.id.list_oneline_txt_title);
			hymn.textView_rating =(TextView)convertView.findViewById(R.id.list_oneline_txt_rating);
			hymn.textView_familiarity =(TextView)convertView.findViewById(R.id.list_oneline_txt_familiarity);
			hymn.textView_times =(TextView)convertView.findViewById(R.id.list_oneline_txt_times);
			
			convertView.setTag(hymn);
		}else {
			hymn = (Hymn)convertView.getTag();
		}
		
		hymn.textView_index.setText( data.get(position).get(COL_INDEX).toString() );
		hymn.textView_title.setText( data.get(position).get(COL_TITLE).toString() );
		hymn.textView_rating.setText( data.get(position).get(COL_RATING).toString() );
		hymn.textView_familiarity.setText( data.get(position).get(COL_FAMILIARITY).toString() );
		hymn.textView_times.setText( data.get(position).get(COL_TIMES).toString() );
		
		return convertView;
	}
	
	public final class Hymn {   
	    public TextView textView_index;   
	    public TextView textView_title;   
	    public TextView textView_rating;   
	    public TextView textView_familiarity;   
	    public TextView textView_times;   
	}  
}
